#!/usr/bin/env python

import random, io, linecache


from flask import Flask, render_template
from flask_bootstrap import Bootstrap
app = Flask(__name__)

bootstrap = Bootstrap(app)

def suiji():
      suijishu1 = random.randint(0,19)
      return suijishu1


@app.route('/')
def xianshi0():
    return "nihao "

@app.route('/s')
def xianshi():

    text = random.randint(0,19)
    fp = io.open("/home/b-liujw/jieguo.txt",'rb')
    quduhangshu = len(fp.readlines())
    fp.close()
    text = linecache.getlines("/home/b-liujw/jieguo.txt", quduhangshu)
    linecache.clearcache()
    linecache.checkcache("/home/b-liujw/jieguo.txt")
    text2 = linecache.getlines("/home/b-liujw/jieguo.txt", quduhangshu)

    return render_template('jieguo.html', sjs= text) 

@app.route('/s2')
def xianshi2():
    with io.open("/home/b-liujw/jieguo.txt") as f:
      txt=f.readlines()
    keys=[k for k in range(0,len(txt))]
    result={k:v for k,v in zip(keys,txt[::-1])}
    for i in range(1):
      print result[i]
    return render_template('jieguo.html', sjs = result[i])

@app.route('/s3')
def xianshi3():
    with io.open("/home/b-liujw/jieguo.txt") as f:
      txt=f.readlines()
    keys=[k for k in range(0,len(txt))]
    result={k:v for k,v in zip(keys,txt[::-1])}
    for i in range(1):
      print result[i]
    return render_template('jieguo.html', sjs = result)

@app.route('/s4')
def xianshi4():
    with io.open("/home/b-liujw/jieguo.txt") as f:
      txt=f.readlines()
    keys=[k for k in range(0,len(txt))]
    result={k:v for k,v in zip(keys,txt[::-1])}
    #for i in range(1):
      #print result[i]
    return render_template('jieguo.html', sjs = result[0],
                                 sjs2 = result[1], sjs3 = str(result[2]))

@app.route('/s5')
def xianshi5():
    with io.open("/home/b-liujw/jieguo.txt") as f:
      txt=f.readlines()
    keys=[k for k in range(0,len(txt))]
    result={k:v for k,v in zip(keys,txt[::-1])}
    fenge1 = result[0].split("/")
    return render_template('1_flaskbootstrap_test.html', sj = fenge1[0],
                                 jg = fenge1[1], jl = fenge1[2])

if __name__ == "__main__":
  app.run(host="0.0.0.0", port=8081, debug = True)

